import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/widgets/bottom_sheet/got_it_tip_bottom_sheet.dart';
import 'package:flutter/material.dart';

const Color _kProgressBackgroundColor = Colors.grey;

class BaseDialog implements DialogManager {
  @override
  Future<T> showErrorDialog<T>(
      {BuildContext context, String text, bool canDismiss = false}) {
    return showGotItTipBottomSheet(context, text);
    // return showDialog<T>(
    //   context: context,
    //   barrierDismissible: canDismiss,
    //   builder: (BuildContext context) => Material(
    //     type: MaterialType.transparency,
    //     child: Center(
    //       child: Container(
    //         width: getDp(200),
    //         height: getDp(200),
    //         alignment: Alignment.center,
    //         decoration: BoxDecoration(
    //           color: Colors.black45,
    //           borderRadius: BorderRadius.circular(
    //             getDp(16),
    //           ),
    //         ),
    //         child: Column(
    //           children: <Widget>[
    //             SizedBox(
    //               width: getDp(50),
    //               height: getDp(50),
    //               child: Icon(
    //                 Icons.close,
    //                 size: getDp(50),
    //                 color: Colors.red,
    //               ),
    //             ),
    //             SizedBox(
    //               height: getDp(15),
    //             ),
    //             Text(
    //               text,
    //               style: Theme.of(context).textTheme.bodyText2,
    //             ),
    //           ],
    //         ),
    //       ),
    //     ),
    //   ),
    // );
  }

  @override
  Future<T> showLoadingDialog<T>(
      {BuildContext context, String text, bool canDismiss = false}) {
    return showDialog<T>(
      context: context,
      barrierDismissible: canDismiss,
      builder: (BuildContext context) => WillPopScope(
        onWillPop: () => Future.value(canDismiss),
        child: Material(
          type: MaterialType.transparency,
          child: Center(
            child: Container(
              width: getDp(150),
              height: getDp(150),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: Colors.black45,
                borderRadius: BorderRadius.circular(
                  getDp(16),
                ),
              ),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  SizedBox(
                    width: getDp(50),
                    height: getDp(50),
                    child: CircularProgressIndicator(
                      strokeWidth: getDp(2),
                    ),
                  ),
                  SizedBox(
                    height: getDp(15),
                  ),
                  Text(
                    text,
                    style: Theme.of(context)
                        .textTheme
                        .bodyText1
                        .copyWith(color: Theme.of(context).canvasColor),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  @override
  Future<T> showSuccessDialog<T>(
      {BuildContext context, String text, bool canDismiss = false}) {
    return showDialog<T>(
      context: context,
      barrierDismissible: canDismiss,
      builder: (BuildContext context) => Material(
        type: MaterialType.transparency,
        child: Center(
          child: Container(
            width: getDp(200),
            height: getDp(200),
            alignment: Alignment.center,
            decoration: BoxDecoration(
              color: Colors.black45,
              borderRadius: BorderRadius.circular(
                getDp(16),
              ),
            ),
            child: Column(
              children: <Widget>[
                SizedBox(
                  width: getDp(50),
                  height: getDp(50),
                  child: Icon(
                    Icons.done,
                    size: getDp(50),
                    color: Colors.green,
                  ),
                ),
                SizedBox(
                  height: getDp(15),
                ),
                Text(
                  text,
                  style: Theme.of(context).textTheme.bodyText2,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  @override
  Future<T> showProgressDialog<T>(
      {BuildContext context,
      String title,
      bool canDismiss = false,
      ProgressValueController controller}) async {
    return await showDialog<T>(
      context: context,
      barrierDismissible: canDismiss,
      builder: (BuildContext context) => Material(
        type: MaterialType.transparency,
        child: Center(
          child: Container(
            width: getDp(150),
            height: getDp(150),
            alignment: Alignment.center,
            decoration: BoxDecoration(
              color: Colors.black45,
              borderRadius: BorderRadius.circular(
                getDp(16),
              ),
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                ValueListenableBuilder<ProgressValue>(
                  valueListenable: controller,
                  builder: (BuildContext context, ProgressValue value,
                      Widget child) {
                    return SizedBox(
                      width: getDp(50),
                      height: getDp(50),
                      child: Stack(
                        children: [
                          Positioned.fill(
                            child: CircularProgressIndicator(
                              strokeWidth: getDp(2),
                              backgroundColor: _kProgressBackgroundColor,
                              value: value.percent,
                            ),
                          ),
                          Center(
                            child: Text(
                                '${(value.percent * 100).toStringAsNotFixed(0)}%',
                                style: Theme.of(context)
                                    .textTheme
                                    .bodyText1
                                    .copyWith(
                                        color: Theme.of(context).canvasColor)),
                          )
                        ],
                      ),
                    );
                  },
                ),
                SizedBox(
                  height: getDp(15),
                ),
                Text(
                  title,
                  style: Theme.of(context)
                      .textTheme
                      .bodyText1
                      .copyWith(color: Theme.of(context).canvasColor),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  @override
  void showToast({BuildContext context, String content}) {
    Toast().showToast(
        context: context,
        message: content,
        style: Theme.of(context).textTheme.bodyText2.copyWith(
              color: Theme.of(context).colorScheme.surface,
            ));
  }
}
